package com.bjbn.controller;

import com.alibaba.fastjson.JSONObject;
import com.bjbn.bean.ApiCallParams;
import com.bjbn.bean.ApiResult;
import com.bjbn.service.DataphinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 应急管理系统
 */
@RestController
@RequestMapping("/dataphin")
@Slf4j
public class Dataphin4EvcApiController {

    @Autowired
    DataphinService dataphinService;

    /**
     * 物资
     * @param orderByList
     * @param pageStart
     * @param pageSize
     * @return
     */
    @RequestMapping("/data_twin_ads_evc_ecv_material_df")
    public JSONObject ads_evc_ecv_material_df(@RequestParam(required = false, defaultValue = "") String orderByList,
                                             @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                             @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,library_name,library,store_way,phone,subordinate_unit,subordinate_depart,address,linkman,material_name,material_type,material_brand,material_model,store_count,count_unit,expire_date,main_function,remark,create_by,create_time,del";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10369");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");

        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }

    /**
     * 预案任务连线
     * @param orderByList
     * @param pageStart
     * @param pageSize
     * @return
     */
    @RequestMapping("/data_twin_ads_evc_ecv_plan_task_connection")
    public JSONObject ads_evc_ecv_plan_task_connection(@RequestParam(required = false, defaultValue = "") String orderByList,
                                                      @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                                      @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,farther_node_id,chooseline,line,parent_index,children_node_id,plan_task_id,version,plan_id";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10372");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");

        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }

    /**
     * 预案
     * @param orderByList
     * @param pageStart
     * @param pageSize
     * @return
     */
    @RequestMapping("/data_twin_ads_evc_ecv_plan_df")
    public JSONObject ads_evc_ecv_plan_df(@RequestParam(required = false, defaultValue = "") String orderByList,
                                         @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                         @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,create_by,create_time,plan_name_id,action_instruction_code,version,plan_name,code,keyword,refer_plan_id,make_unit,editor,make_time,remark,plan_type_code,old_plan_id,scope,aircraft_type,update_by,update_time,sys_org_code,have_edit,del_flag,plan_type,evc_sort,effect_time,scope_array";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10370");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");

        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }

    /**
     * 预案名称
     * @param orderByList
     * @param pageStart
     * @param pageSize
     * @return
     */
    @RequestMapping("/data_twin_ads_evc_ecv_plan_name_df")
    public JSONObject ads_evc_ecv_plan_name_df(@RequestParam(required = false, defaultValue = "") String orderByList,
                                              @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                              @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,name,short_name,info_template,code,plan_type_code,create_by,create_time,update_by,update_time,sys_org_code,ecv_sort,attachment_name,attachment_path";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10371");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");

        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }

    /**
     * 预案任务
     * @param orderByList
     * @param pageStart
     * @param pageSize
     * @return
     */
    @RequestMapping("/data_twin_ads_evc_ecv_plan_task_df")
    public JSONObject ads_evc_ecv_plan_task_df(@RequestParam(required = false, defaultValue = "") String orderByList,
                                              @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                              @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,title,subtitle,number_id,place,start_type,create_time,update_time,plan_id,category,evc_status,connection_plan_id,begin_trigger_point_id,template_task_type,begin_trigger_point_content,begin_trigger_point,page_mark,save_request_url,publish_request_url,description,depart_id,before_task_id,together_task_id,width,height,x,y,choose,is_empty_btn,create_by,update_by,sys_org_code,evc_sort,version,load_flag,is_end_task";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10373");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");

        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }

    /**
     * 物资库
     * @param orderByList
     * @param pageStart
     * @param pageSize
     * @return
     */
    @RequestMapping("/data_twin_ads_evc_material_library_df")
    public JSONObject ads_evc_material_library_df(@RequestParam(required = false, defaultValue = "") String orderByList,
                                                 @RequestParam(required = false, defaultValue = "1") Integer pageStart,
                                                 @RequestParam(required = false, defaultValue = "20") Integer pageSize) {
        String fields = "id,create_by,create_time,library_name,library_code,address,subordinate_unit,subordinate_depart,linkman,phone,del";
        ApiCallParams apiCallParams = new ApiCallParams();
        apiCallParams.setApiId("10374");
        apiCallParams.setApiType("LIST");
        apiCallParams.setAppKey("200000226");
        apiCallParams.setAppSecret("d43bc101cb3b4add8554f821b568c84c");
        apiCallParams.setApiReturnFields(fields);
        apiCallParams.setListType("LIST");

        apiCallParams.setPageStart(pageStart);
        apiCallParams.setPageSize(pageSize);
        apiCallParams.setOrderByList(orderByList);
        ApiResult apiResult = dataphinService.getDataphinData(apiCallParams);

        if (apiResult.getResultCode() == 200) {
            return JSONObject.parseObject(apiResult.getResultBody());
        } else {
            return JSONObject.parseObject(apiResult.getError());
        }
    }
}
